﻿/*常客升级相关方法
 * 
 */
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Text;
using EZCRS.HCMS.Bll;
using EZCRS.HCMS.Bll.userinfo;

namespace EZCRS.HCMS.myajax
{
    public class CardUserUpgrade:MainBase
    {
        ArrayList arrRecord;
        //记录数量
        int iRecordCount = 0;
        //总页数
        int iPageCount = 0;


        /// <summary>
        /// 查询带升级用户列表
        /// </summary>
        /// <param name="cpage">页数</param>
        /// <param name="search">条件</param>
        /// <param name="orderkey">排序</param>
        /// <returns></returns>
        [AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
        public ArrayList userlist(int cpage, string search, string orderkey)
        {
            #region

            arrRecord = new ArrayList();

            string[] searchlist = search.Split('|');
            string gid = BasGroupId.ToString();

            if (searchlist.Length != 2 || gid == "")
            {
                arrRecord.Add("error!");
                return arrRecord;
            }

            string orders="";
            
            switch(orderkey)
            {
                case "1":
                    orders = " username desc ";
                    break;
                case "11":
                    orders = " username ";
                    break;
                case "2":
                    orders = " mobnumb desc ";
                    break;
                case "22":
                    orders = " mobnumb ";
                    break;
                case "3":
                    orders = " email desc ";
                    break;
                case "33":
                    orders = " email ";
                    break;
                case "4":
                    orders = " usrfirstname desc ";
                    break;
                case "44":
                    orders = " usrfirstname ";
                    break;
                case "5":
                    orders = " logid desc ";
                    break;
                case "55":
                    orders = " logid ";
                    break;
                default:
                    orders=" logid desc ";
                    break;
            }

            int pageindex = Convert.ToInt32(cpage);
            DataSet ds = null;

            Bllcardinfo admuser = new Bllcardinfo();
            ds = admuser.upgradelist(gid, searchlist[0], searchlist[1], orders, cpage);


            DataTable dt = ds.Tables[0];
            iRecordCount = Convert.ToInt32(ds.Tables[1].Rows[0][0].ToString());

            iPageCount = (iRecordCount / CFun.PageSize);
            if (iRecordCount % CFun.PageSize > 0)
            {
                iPageCount++;
            }

            
            //组合字符串
            string clogid = "";

            StringBuilder strTable = new StringBuilder();
            #region
            strTable.Append("<table border=\"0\" cellpadding=\"1\" cellspacing=\"1\" width=\"100%\"><tr class=\"title1\" height=\"26\"><td width=\"6%\" style=\"color: white;\">"+EZCRS.HCMS.myajax.Site.StrNumb+"</td><td width=\"10%\" style=\"color: white;cursor:hand;\" onclick=\"javascript:setorders('4');\" title=\""+EZCRS.HCMS.myajax.Site.StrKeyRank+"\">"+EZCRS.HCMS.myajax.Site.StrUserName+"</td><td width=\"10%\"  style=\"color: white;cursor:hand;\" onclick=\"javascript:setorders('5');\" >"+EZCRS.HCMS.myajax.Site.StrUpgrade+"</td><td width=\"20%\" style=\"color: white;\">"+EZCRS.HCMS.myajax.Site.StrUpgradeClass+"</td><td width=\"12%\" style=\"color: white;cursor:hand;\" onclick=\"javascript:setorders('1');\"  title=\""+EZCRS.HCMS.myajax.Site.StrKeyRank+"\">"+EZCRS.HCMS.myajax.Site.StrLogName+"</td><td width=\"6%\" style=\"color: white;cursor:hand;\" onclick=\"javascript:setorders('2');\"  title=\""+EZCRS.HCMS.myajax.Site.StrKeyRank+"\">"+EZCRS.HCMS.myajax.Site.StrMobile+"</td><td width=\"6%\" style=\"color: white;cursor:hand;\" onclick=\"javascript:setorders('3');\"  title=\""+EZCRS.HCMS.myajax.Site.StrKeyRank+"\">"+EZCRS.HCMS.myajax.Site.StrEmail+"</td><td width=\"1%\" style=\"color: white;\"><input type=\"checkbox\" id=\"cbx\" onclick=\"clientselect(this);\"/></td></tr>");
            if (ds.Tables[0].Rows.Count > 0)
            {
                for (int row = 0; row < dt.Rows.Count; row++)
                {
                    clogid += "," + ds.Tables[0].Rows[row]["logid"].ToString();

                    strTable.Append("<tr");
                    if (row % 2 == 0)
                    {
                        strTable.Append(" class='line-odd'");
                    }
                    else
                    {
                        strTable.Append(" class='line-even'");
                    }
                    strTable.Append(" onmouseover=\"currentcolor=this.style.backgroundColor;this.style.backgroundColor='#B9CEEA';\"");
                    strTable.Append(" onmouseout=\"this.style.backgroundColor=currentcolor;\"");
                    strTable.Append(">");
                    string sNo = "";
                    if (((pageindex - 1) * CFun.PageSize + row + 1) < 10)
                    {
                        sNo = "0" + Convert.ToString(row + 1);
                    }
                    else
                    {
                        sNo = Convert.ToString((pageindex - 1) * CFun.PageSize + row + 1);
                    }
                    strTable.Append("<td><div align=\"center\">");
                    strTable.Append(sNo.ToString());
                    strTable.Append("</div></td>");
                    strTable.Append("<td><div align=\"center\">");
                    strTable.Append(ds.Tables[0].Rows[row]["usrfirstname"].ToString() + "." + ds.Tables[0].Rows[row]["usrlastname"].ToString());
                    strTable.Append("</div></td>");

                    strTable.Append("<td><div align=\"center\">");
                    strTable.Append(ds.Tables[0].Rows[row]["uupdate"].ToString());
                    strTable.Append("</div></td>");
                    strTable.Append("<td><div align=\"center\">");
                    strTable.Append(ds.Tables[0].Rows[row]["lvlname"].ToString());
                    strTable.Append("</div></td>");
                    strTable.Append("<td><div align=\"center\">");
                    strTable.Append(ds.Tables[0].Rows[row]["username"].ToString());
                    strTable.Append("</div></td>");
                    strTable.Append("<td><div align=\"center\">");
                    strTable.Append(ds.Tables[0].Rows[row]["mobnumb"].ToString());
                    strTable.Append("</div></td>");
                    strTable.Append("<td><div align=\"center\">");
                    strTable.Append(ds.Tables[0].Rows[row]["email"].ToString());
                    strTable.Append("</div></td>");
                    strTable.Append("<td><div align=\"center\"><input type=\"checkbox\" id=\"cbx" + ds.Tables[0].Rows[row]["logid"].ToString() + "\"></div></td>");
                    strTable.Append("</tr>");
                }
            }
            else
            {
                strTable.Append("<tr height=\"35\" class=\"line-odd\"><td colspan=\"8\" align=\"center\">"+EZCRS.HCMS.myajax.Site.StrNonData+"</td></tr>");
            }
            strTable.Append("</table><input type=\"hidden\" id=\"hidlogid\" value=\""+clogid+"\">");
            #endregion
            //将表格放入arraylist
            arrRecord.Add(strTable.ToString());
            //将总页数放入arraylist
            arrRecord.Add(iPageCount.ToString() == "0" ? "1" : iPageCount.ToString());
            //将总记录数放入arraylist
            arrRecord.Add(iRecordCount.ToString());

            return arrRecord;

            #endregion
        }

        

        /// <summary>
        /// 常客升级 方法
        /// </summary>
        /// <param name="logid">升级表中的id,多个用逗号隔开</param>
        /// <returns></returns>
        [AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
        public string userupgrade(string logid)
        {
            if (logid == "")
            {
                return "0";
            }
            string gid = BasGroupId.ToString();
            int successcount = 0;
            Bllcardinfo auser = new Bllcardinfo();
            string[] uplogid=logid.Split(',');
            foreach (string lid in uplogid)
            {
                if (auser.userupgrade(gid, lid))
                {
                    successcount++;
                }
            }
            return successcount.ToString();
        }

        /// <summary>
        /// 删除升级请求的方法
        /// </summary>
        /// <param name="logid">升级表中的id,多个用逗号隔开</param>
        /// <returns></returns>
        [AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
        public string userdel(string logid)
        {
            string gid = BasGroupId.ToString();

            if (gid == "")
                return "0";

            Bllcardinfo auser = new Bllcardinfo();
            if (auser.upgradedel(gid, logid) > 0)
                return "1";
            else
                return "0";
        }
    }
}
